<template>
  <input class="copy-input" v-model="value" readonly ref="input">
</template>

<script>
export default {
  name: 'copy',
  data () {
    return {
      value: ''
    }
  },
  methods: {
    copy (value, text = '分享链接复制成功~') {
      if (value) {
        this.value = value
        this.$nextTick(() => {
          this.$refs.input.select()
          document.execCommand('copy')
          this.$toast.success(text)
        })
      }
    }
  }
}
</script>

<style scoped>
  .copy-input {
    position: fixed;
    width: 1px;
    height: 1px;
    top: -100px;
    z-index: 0;
    opacity: 0;
  }

</style>
